package com.huawei.appgallery.assistantdock.base.externalaction.openviewaction;

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import com.huawei.gamebox.plugin.gameservice.bean.GameInfo;
import com.huawei.secure.android.common.intent.SafeIntent;
import o.beq;
import o.bgt;
import o.bgu;
import o.ces;
import o.cet;
import o.ceu;
import o.dex;
import o.Logger;
import o.ContentManager;
import o.dys.a;
import o.fae;
import o.fam;

public class RemoteBuoyAction extends IOpenViewAction {
    private static final String HIGAME_PACKAGE_NAME = "com.huawei.gamebox";
    public static final String REMOTE_BUOY_PARAM = "params";
    public static final String REMOTE_BUOY_URI = "uri";
    private static final int REQUEST_ID = 1000;
    private static final String RESTORE_GAMEBOX_PATHJUDGE = "gamebox";
    private static final int RESTORE_GAMEBOX_VERSION = 100200000;
    public static final String RESTORE_REPORTBI_URI = "bi_uri";
    public static final String RESTORE_TARGET_VERSION = "target_version";
    public static final String RESUME_GAMEBOX_ACTION = "com.huawei.appgallery.buoy.resume.gamebox";
    private static final String TAG = "RemoteBuoyAction";

    class RemoteBuoyCallback implements ces {
        private Context context;
        private Bundle params;
        private String reportBiUri;
        private String uri;

        public RemoteBuoyCallback(Context context, String str, Bundle bundle, String str2) {
            this.uri = str;
            this.params = bundle;
            this.context = context;
            this.reportBiUri = str2;
        }

        public void onResult(int i) {
            Logger.ˎ(RemoteBuoyAction.TAG, "Restore result=" + i);
            beq.ˋ(i, "com.huawei.gamebox", this.reportBiUri);
            if (TextUtils.isEmpty(this.uri)) {
                Logger.ˎ(RemoteBuoyAction.TAG, "the uri is null, nothing to do");
            } else if (i == 2000 || i == 2001 || i == 2002) {
                RemoteBuoyAction.this.openRemoteActivity();
            } else if (i == 2100) {
                RemoteBuoyAction.this.openLocalWindow(this.context, this.uri, this.params);
                RemoteBuoyAction.this.callback.finish();
            } else if (i == 2300 || i == 2101 || i == 2102 || i == 2103 || i == 2301) {
                RemoteBuoyAction.this.callback.finish();
            }
        }
    }

    private void openLocalWindow(Context context, String str, Bundle bundle) {
        dex ˋ = bgu.ˋ(str);
        if (ˋ != null) {
            fam.ॱ().ˏ(context, ˋ, bundle);
        }
    }

    public RemoteBuoyAction(a aVar, SafeIntent safeIntent) {
        super(aVar, safeIntent);
    }

    public void onAction() {
        if (this.intent == null) {
            Logger.e(TAG, "intent is null");
        } else if (this.callback instanceof Activity) {
            String stringExtra = this.intent.getStringExtra(REMOTE_BUOY_URI);
            Bundle bundleExtra = this.intent.getBundleExtra(REMOTE_BUOY_PARAM);
            String stringExtra2 = this.intent.getStringExtra(RESTORE_REPORTBI_URI);
            new ceu((Activity) this.callback).ˊ(new cet("com.huawei.gamebox", RESTORE_GAMEBOX_PATHJUDGE, this.intent.getIntExtra(RESTORE_TARGET_VERSION, RESTORE_GAMEBOX_VERSION)), new RemoteBuoyCallback((Activity) this.callback, stringExtra, bundleExtra, stringExtra2));
        } else {
            Logger.e(TAG, "callback is not Activity");
        }
    }

    public void onActivityResult(int i, int i2, Intent intent) {
        if (i == 1000 && i2 != 999) {
            Context ˋ = ContentManager.getInstant().getContext();
            fae ˏ = fam.ॱ().ˏ();
            GameInfo gameInfo = null;
            if (ˏ != null) {
                gameInfo = ˏ.getGameInfo();
            }
            new bgt().ˏ(ˋ, this.intent.getStringExtra(REMOTE_BUOY_URI), this.intent.getBundleExtra(REMOTE_BUOY_PARAM), gameInfo);
        }
        this.callback.finish();
    }

    private void openRemoteActivity() {
        Intent intent = new Intent("com.huawei.gamebox.transferactivity");
        intent.setPackage("com.huawei.gamebox");
        try {
            this.callback.startActivityForResult(intent, 1000);
        } catch (ActivityNotFoundException e) {
            Logger.ˋ(TAG, "ActivityNotFoundException :" + e.toString());
        }
    }

    public boolean isFinishOnResume() {
        return false;
    }
}
